package com.chaoma.web.controller.cm;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chaoma.common.core.controller.BaseController;
import com.chaoma.common.core.domain.AjaxResult;
import com.chaoma.system.domain.CmFactory;
import com.chaoma.system.service.ICmFactoryService;
import com.chaoma.common.utils.poi.ExcelUtil;
import com.chaoma.common.core.page.TableDataInfo;

/**
 * 抄码信息Controller
 *
 * @author chaoma
 * @date 2023-10-07
 */
@RestController
@RequestMapping("/system/cmFactory")
public class CmFactoryController extends BaseController
{
    @Autowired
    private ICmFactoryService cmFactoryService;

    /**
     * 查询抄码信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmFactory cmFactory)
    {
        startPage();
        List<CmFactory> list = cmFactoryService.selectCmFactoryList(cmFactory);
        return getDataTable(list);
    }

    /**
     * 导出抄码信息列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmFactory cmFactory)
    {
        List<CmFactory> list = cmFactoryService.selectCmFactoryList(cmFactory);
        ExcelUtil<CmFactory> util = new ExcelUtil<CmFactory>(CmFactory.class);
        util.exportExcel(response, list, "抄码信息数据");
    }

    /**
     * 获取抄码信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cmFactoryService.selectCmFactoryById(id));
    }

    /**
     * 新增抄码信息
     */
    @PostMapping
    public AjaxResult add(@RequestBody CmFactory cmFactory)
    {
        return toAjax(cmFactoryService.insertCmFactory(cmFactory));
    }

    /**
     * 修改抄码信息
     */
    @PutMapping
    public AjaxResult edit(@RequestBody CmFactory cmFactory)
    {
        return toAjax(cmFactoryService.updateCmFactory(cmFactory));
    }

    /**
     * 删除抄码信息
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmFactoryService.deleteCmFactoryByIds(ids));
    }
}
